package PTA.ch05;
import java.util.Scanner;
public class ex04 {
    public static void main(String[] args) {


        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        int m = sc.nextInt();
        ArrayUtil in = new ArrayUtil();
        for (int j = 0; j < m; j++) {
            int begin = sc.nextInt();
            int end = sc.nextInt();
            in.findMax(arr, begin, end);
        }
    }
}
class ArrayUtil{
    public  void findMax(int[] arr, int begin, int end){
        if(begin>=end){
            System.out.println("IllegalArgumentException: begin:"+begin+">= end"+end);
        }else if(begin<0){
            System.out.println("IllegalArgumentException: begin:"+begin+"<0");
        }else if(end>arr.length){
            System.out.println("java.lang.IllegalArgumentException: end:"+end+" > arr.length");
        }else{
            int max=0;
            for(int q=begin;q<end;q++){
                if(arr[q]>max){
                    max=arr[q];
                }
            }
            System.out.println(max);
        }

    }


}


